//
//  SubUserInfoUpdateTableViewController.m
//  CarTown
//
//  Created by xionghao on 15/9/5.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "SubUserInfoUpdateTableViewController.h"

#import "UpdatepassViewController.h"
#import "NoramlTableViewCell.h"
#import "NoramlCellMode.h"
#import "Puser.h"
@interface SubUserInfoUpdateTableViewController ()
@property (nonatomic,strong) NoramlCellMode *usernamemode;
@property (nonatomic,strong) NoramlCellMode *namemode;
@property (nonatomic,strong) NoramlCellMode *jobmode;
@property (nonatomic,strong) NoramlCellMode *phonemode;
@property (nonatomic,strong) NoramlCellMode *passwordmode;
@property (nonatomic,strong) NoramlCellMode *bindphonemode;



@property (nonatomic,strong) NSMutableArray *dataarray;
@property (nonatomic,strong) Puser *user;

@end

@implementation SubUserInfoUpdateTableViewController



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)dataarray{
    if ( _dataarray==nil) {
        _dataarray=[NSMutableArray array];
    }
    return  _dataarray;
}

-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 16;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"修改业务员信息";
    
      [self setupdata];
    
    
    
    
    // Do any additional setup after loading the view from its nib.
}

-(void)setupdata{
    self.usernamemode=[[NoramlCellMode alloc]init];
    self.usernamemode.title=@"账号";
    self.usernamemode.detail=self.mode.com_username;
    self.namemode=[[NoramlCellMode alloc]init];
    self.namemode.title=@"姓名";
    self.namemode.detail=self.mode.com_ctusername;
    self.namemode.block=^{
        UpdatepassViewController *vc=[UpdatepassViewController viewcontroller];
        vc.com_id=self.user.com_id;
        vc.child_id=self.mode.com_id;
        vc.text=self.namemode.detail;
        vc.type=NAMETYPE;
        vc.block=^(NSString *str){
            self.namemode.detail=str;
            [self.tableView reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    };
    self.jobmode=[[NoramlCellMode alloc]init];
    self.jobmode.title=@"职位";
    self.jobmode.detail=self.mode.com_job;
    self.jobmode.block=^{
        UpdatepassViewController *vc=[UpdatepassViewController viewcontroller];
        vc.com_id=self.user.com_id;
        vc.child_id=self.mode.com_id;
        vc.text=self.jobmode.detail;
        vc.type=JOBTYPE;
        vc.block=^(NSString *str){
            self.jobmode.detail=str;
            [self.tableView reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    self.phonemode=[[NoramlCellMode alloc]init];
    self.phonemode.title=@"联系电话";
    self.phonemode.detail=self.mode.com_ctphone;
    self.phonemode.block=^{
        UpdatepassViewController *vc=[UpdatepassViewController viewcontroller];
        vc.com_id=self.user.com_id;
        vc.child_id=self.mode.com_id;
        vc.text=self.phonemode.detail;
        vc.type=PHONETYPE;
        vc.block=^(NSString *str){
            self.phonemode.detail=str;
            [self.tableView reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    };
    self.passwordmode=[[NoramlCellMode alloc]init];
    self.passwordmode.title=@"修改密码";
    self.passwordmode.detail=@"请重新设置密码";
    self.passwordmode.block=^{
        UpdatepassViewController *vc=[UpdatepassViewController viewcontroller];
        vc.com_id=self.user.com_id;
        vc.child_id=self.mode.com_id;
        
        vc.type=PASSTYPE;
        
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    self.bindphonemode=[[NoramlCellMode alloc]init];
    self.bindphonemode.title=@"绑定的手机号";
    self.bindphonemode.detail=self.mode.bindtephone?self.mode.bindtephone:@"未绑定";
    self.bindphonemode.block=^{
        UpdatepassViewController *vc=[UpdatepassViewController viewcontroller];
        vc.com_id=self.user.com_id;
        vc.child_id=self.mode.com_id;
        vc.text=self.bindphonemode.detail;
        vc.type=BINDTYPE;
        vc.block=^(NSString *str){
            self.bindphonemode.detail=str;
            [self.tableView reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    [self.dataarray addObject:@[self.usernamemode]];
    [self.dataarray addObject:@[self.namemode,self.phonemode,self.jobmode,self.passwordmode,self.bindphonemode]];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.dataarray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *array=self.dataarray[section];
    return array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    NoramlCellMode *cellmode=array[indexPath.row];
    NoramlTableViewCell *cell=[NoramlTableViewCell cellWithTableView:tableView];
    if (indexPath.section==0) {
        cell.accessoryType=UITableViewCellAccessoryNone;
    }else{
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text=cellmode.title;
    cell.detailTextLabel.text=cellmode.detail;
    if ([cellmode  isEqual:self.passwordmode] ) {
        cell.detailTextLabel.textColor=[UIColor lightGrayColor];
    }else{
        cell.detailTextLabel.textColor=UIColorWithRGB(51, 51, 51);
    }
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    NoramlCellMode *mode=array[indexPath.row];
    if (mode.block) {
        mode.block();
    }
}





/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
